package com.itheima.jobs;

import com.itheima.constant.RedisConst;
import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.JedisPool;

import java.util.Set;

@Component
public class ClearImgJob {

    @Autowired
    JedisPool jedisPool;
    public void clear(){

//        找出垃圾图片   两个集合的差值
        Set<String> sdiff = jedisPool.getResource().sdiff(RedisConst.SETMEAL_PIC_RESOURCES, RedisConst.SETMEAL_PIC_DB_RESOURCES);

//    删除七牛云上的图片
        for (String s : sdiff) {
            QiniuUtils.deleteFileFromQiniu(s);
//redis图片名称清除
            jedisPool.getResource().srem(RedisConst.SETMEAL_PIC_RESOURCES,s);
        }


    }
}
